﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __AE37BA46_937B_48cd_8340_D38B540321E3__
#define __AE37BA46_937B_48cd_8340_D38B540321E3__

#include "../macro/head.h"
#include "../release/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 
namespace xos
{
    // 
    // file interfacce
    // 
    class i_file : public i_release
    {
    public:
        // 
        // access defin
        // 
        enum enumFileAccessFlag
        {
            FILE_WRITE  = 0x01,
            FILE_READ   = 0x02
        };

        // 
        // file share define
        // 
        enum enumFileShareFlag
        {
            SHARE_WRITE  = 0x01,
            SHARE_READ   = 0x02
        };

        // 
        // file create type define
        // 
        enum enumFileOpenFlag
        {
            FILE_CREATE = 0x01,
            FILE_OPEN   = 0x02,
            FILE_TRUNC  = 0x04
        };

        // 
        // random move file pointer from ...
        // 
        enum enumFilePos
        {
            FILE_POS_BEGIN,
            FILE_POS_CUR,
            FILE_POS_END
        };

        // 
        // dir or file ?
        // 
        enum enumFileType
        {
            FILE_TYPE_NONE,
            FILE_TYPE_FILE,
            FILE_TYPE_DIR
        };

    public:
        virtual ~i_file(){}

    public:
        //////////////////////////////////////////////////////////////////////////////////
        // 
        // open file
        // 
        virtual int open( const char * lpszFileName, unsigned long ulAccessFlag, unsigned long ulShareMode, unsigned long ulCreateFlag ) = 0;

        // 
        // get file time
        // 
        virtual int get_file_time( xos::xos_i64 * lpCreateTime, xos::xos_i64 * lpAccessTime, xos::xos_i64 * lpModifyTime ) = 0;

        // 
        // get file or dir name
        // 
        virtual const char * get_file_name( char * lpszFileName, int nLen, int * pnLenNeeded ) = 0;

        // 
        // is file or dir ? 
        // 
        virtual enumFileType get_file_type() = 0;

        // 
        // move file pointer to ...
        // 
        virtual int set_file_pos( enumFilePos enumFrom, xos_i64 iPos64, xos_i64 * lpSeek64 ) = 0;

        // 
        // get current file pointer
        // 
        virtual int get_file_pos( xos_i64 * lpSize64 ) = 0;

        // 
        // get file size
        // 
        virtual int get_file_size( xos_i64 * lpSize64 ) = 0;

        // 
        // commit file disk space.
        // 
        virtual int commit_file( xos_i64 iPos64 ) = 0;

        // 
        // write file data
        // 
        // -1 means failed. other , write bytes
        // 
        virtual int write( const void * lpBuf, unsigned long ulBufSize ) = 0;

        // 
        // read file data
        // 
        // -1 means failed. other , read bytes
        // 
        virtual int read( void * lpBuf, unsigned long ulBufSize ) = 0;

        // 
        // close file handle
        // 
        virtual int close() = 0;
    };
}

#endif // __AE37BA46_937B_48cd_8340_D38B540321E3__
